/**
 * Created by chenshengli on 2015/7/1 0001.
 */
define([], function () {
    return function ($scope, $rootScope, $location, $routeParams, $http, $resourceService) {

        $scope.addNewEnv = function () {
            var code = $scope.envCode;
            var name = $scope.envName;
            if (!code) {
                alert("环境编码为空！");
                return;
            }
            if (!name) {
                alert("环境名称为空！");
                return;
            }
            $http({
                method: "PUT",
                url: "api/managers/env",
                data: {code: code, name: name},
                cache: false
            }).success(function (data, status) {
                if (data.status == "ok") {
                    alert("环境添加成功！");
                } else {
                    alert("环境添加失败！");
                }
                window.location.reload(true);
            }).error(function (data, status) {
                alert("环境添加异常！");
                window.location.reload(true);
            });
        }
        $resourceService.queryEnvs($http,$scope);


        $scope.deleteEnv = function (envId) {
            if (!window.confirm("是否要删除该环境？")) {
                return;
            }
            $http({
                method: "DELETE",
                url: "api/managers/env/" + envId
            }).success(function (data, status) {
                if (data.status == "ok") {
                    alert("环境删除成功！");
                } else {
                    alert("环境删除失败！");
                }
                window.location.reload(true);
            }).error(function (data, status) {
                alert("环境删除异常！");
                //window.location.reload(true);
            });
        }

        $('.menu .item').tab();
    }
});